﻿using System;
using System.Collections.Generic;
using viNews.Classes;
using viNews.Controllers;
using visinia.SmartEngine;
using visinia.SmartEngine.Modules;

public partial class Modules_viNews_News : WebModule
{
    protected void Page_Load(object sender, EventArgs e)
    {
        WebPageController.AddScriptLink(Page, WebRoots.GetModulesRoot + "viNews/News/pager.js");
        string page = Request.QueryString["Page"];
        int CurrentPage = 0;
        Int32.TryParse(page, out CurrentPage);
        Bind(CurrentPage);
    }

    private void Bind(int CurrentPage)
    {           
        int pages = DataFilterController.GetFilteredDataPagesCount(ModuleId);
        CurrentPageState.Value = CurrentPage.ToString();
        if (pages >= CurrentPage)
        {
            if (pages > CurrentPage)
                pager_Next.Visible = true;
            else
                pager_Next.Visible = false;
            if (CurrentPage > 0)
                pager_Prev.Visible = true;
            else
                pager_Prev.Visible = false;
            List<News> list = DataFilterController.GetFilteredData(ModuleId, CurrentPage);
            NEWS.DataSource = list;
            NEWS.DataBind();
        }
    }    
    
    public int GetCommentsCount(int NewsId)
    {
        return CommentController.GetCommentsCount(NewsId);
    }   
}
